package com.examination.client.mapper;

import com.examination.client.domian.dto.CourierSiteInfoDTO;
import com.examination.client.domian.vo.TodaySiteStorageStatisticsVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @BelongsProject: kuaiDiClient
 * @BelongsPackage: com.examination.client.mapper
 * @Author: tm
 * @CreateTime: 2022-10-21  18:22
 * @Description: TODO
 * @Version: 1.0
 */
public interface CourierSiteInfoMapper {

    @Select("SELECT s.id siteId, s.site_name siteName, s.subsite_in subsiteIn, i.num storageQuantity FROM courier_site s " +
            "LEFT JOIN (SELECT next_site_id, COUNT(next_site_id) num FROM courier_info " +
            "WHERE  date_format(storage_time,'%Y-%m-%d') = #{dateStr} AND delete_status = '0' " +
            "GROUP BY next_site_id) i ON s.id = i.next_site_id " +
            "WHERE s.id in (${ids})" +
            "AND delete_status = '0'")
    List<CourierSiteInfoDTO> getCourierSiteInfo(@Param("ids")String ids, @Param("dateStr") String dateStr);

    @Select("SELECT count(*) storageQuantity FROM courier_info " +
            "WHERE date_format(storage_time,'%Y-%m-%d') = #{dateStr} " +
            "AND next_site_id = #{siteId} " +
            "AND delete_status = '0'")
    TodaySiteStorageStatisticsVO getTodaySiteStorageStatistics(@Param("siteId")Integer siteId, @Param("dateStr") String dateStr);

}